#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;

int main() {
  Mat src = imread("../images/2.jpg");
  if (src.empty()) {
    cout << "could not load image.." << endl;
    return -1;
  }
  namedWindow("opencv setup demo", CV_WINDOW_AUTOSIZE);
  imshow("opencv setup demo", src);
  Mat dst = Mat::zeros(src.size(), src.type());
  /*
    int cols = (src.cols - 1) * src.channels();
    int offsetx = src.channels();
    int rows = src.rows;
    for (int row = 1; row < (rows - 1); row++) {
      const uchar* current = src.ptr<uchar>(row);
      const uchar* previous = src.ptr<uchar>(row - 1);
      const uchar* next = src.ptr<uchar>(row + 1);
      uchar* output = dst.ptr<uchar>(row);
      for (int col = offsetx; col < (cols - 1); col++) {
        output[col] = saturate_cast<uchar>(
            5 * current[col] - (current[col - offsetx] + current[col + offsetx]
    + previous[col] + next[col]));
      }
    }
  */
  double t = getTickCount();
  Mat kernel = (Mat_<char>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
  filter2D(src, dst, src.depth(), kernel);

  double timeconsume = (getTickCount() - t) / getTickFrequency();
  cout << "time consumer" << timeconsume << endl;

  namedWindow("contrast image demo", CV_WINDOW_AUTOSIZE);
  imshow("contrast image demo", dst);

  waitKey(0);
  return -1;
}